********************************************************************************
***************************Regression analyses*******************************
********************************************************************************


*Globals

global std c.female c.hed ib2.catue ib1.hhtype i.year
global ctr AT BE DE DK EL ES FI FR IE IT NL PT SE UK	


	**Interactions
	foreach x in 	itfob ifob igen irgen isgen icon ircon iscon ///
					iwait irwait iswait icov ircov iscov irep irrep isrep idur irdur isdur ///
					itr1 itr2 itr3 ietr1 ietr2 iotr1 iotr2 {
		global `x'
		local y=substr("`x'",2,6)
		foreach z in $ses {
			global `x' $`x' c.`y'#`z'
		}
	}


*Load data for main analysis

use "t0", clear


*Standardize sample
qui reg ub fob c.age $std
gen n=e(sample)
keep if n==1

	**Standardize continous variable (age)
	gen rage=age-r(mean) 
	egen sage=std(age)

	gen rage_sq=rage*rage
	gen sage_sq=sage*sage

	la var rage "Age"
	la var sage "Age"
	la var rage_sq "Age$^2$"
	la var sage_sq "Age$^2$"
	
	**Add to global for micro-level controls
	global ses c.sage c.sage_sq $std




*Save for later use

save "$off\t-set", replace


*Regression Analyses

*Empty model
meqrlogit ub c.fob i.year || ctyear:, mle intpoints(10) stddev
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store m1

*Micro-level controls
meqrlogit ub c.fob $ses /// 
|| ctyear:, mle intpoints(10) stddev
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store m2

*Benefit generosity
meqrlogit ub c.fob c.sgen $ses ///
|| ctyear:, mle intpoints(10) stddev
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store m3

*Benefit generosity, interacted
meqrlogit ub c.fob c.sgen $ses /// 
c.sgen#c.fob ///
|| ctyear:, mle intpoints(10) stddev
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store m4

*Benefit generosity, controls interacted
meqrlogit ub c.fob c.sgen $ses ///
c.sgen#c.fob $ifob $isgen ///
|| ctyear:, mle intpoints(10) stddev noomitted
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store m5

*Macro-level controls
meqrlogit ub c.fob c.sgen $ses ///
c.sgen#c.fob $ifob $isgen ///
c.ssk c.smipex c.sgdp1 ///
c.ssk#c.fob c.sgen#c.ssk ///
c.smipex#c.fob c.sgen#c.smipex ///
c.sgdp1#c.fob c.sgen#c.sgdp1 ///
|| ctyear:, mle intpoints(10) stddev noomitted
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store m6

*Time of residency
meqrlogit ub c.tr1 c.tr2 c.tr3 c.sgen $ses ///
c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
c.ssk c.smipex c.sgdp1 ///
c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.sgen#c.ssk ///
c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.sgen#c.smipex ///
c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.sgen#c.sgdp1 ///
|| ctyear:, mle intpoints(10) stddev noomitted
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store m7


global var "fob tr1 tr2 tr3 sgen c.sgen#c.fob c.sgen#c.tr1 c.sgen#c.tr2 c.sgen#c.tr3 ssk sgdp1 smipex female sage sage_sq hed 1.catue 2.catue 3.catue 1.hhtype 2.hhtype 3.hhtype 4.hhtype _cons"

esttab m1 m2 m3 m4 m5 m6 m7 using "regress.tex", ///
stats(n cl icc ll, labels("Observations" "Clusters" "Intra-cluster correlation" "Log-likelihood") fmt(%8.0f %8.0f %8.2f %8.0f)) ///
replace compress label booktabs nodepvars se(2) b(2) ///
mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" "Model 7") nonum noomitted ///
order($var) ///
keep($var) ///
eqlabels("" "") transform(ln*: exp(@) exp(@)) ///
addnote("Interacted controls are included in Model 4 \& Model 5 (not shown here)") ///
varlabels(eq1:_cons "Average intercept (native-born)" lns1_1_1:_cons "Standard deviation of the intercepts") 


*Generate graph (mean-centered scale for benefit generosity (rgen))
meqrlogit ub c.tr1 c.tr2 c.tr3 c.rgen $ses ///
c.rgen#c.tr1  $itr1 c.rgen#c.tr2 $itr2 c.rgen#c.tr3 $itr3 $irgen ///
c.ssk c.smipex c.sgdp1 ///
c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.rgen#c.ssk ///
c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.rgen#c.smipex ///
c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.rgen#c.sgdp1 ///
|| ctyear:, mle intpoints(10) stddev noomitted


margins, dydx(tr1) at(rgen=(-5(0.5)5)) predict(mu fixed)
matrix A=r(table)'

margins, dydx(tr2) at(rgen=(-5(0.5)5)) predict(mu fixed)
matrix B=r(table)'

margins, dydx(tr3) at(rgen=(-5(0.5)5)) predict(mu fixed)
matrix C=r(table)'

svmat A, names(col)
keep b ll ul
gen jap=100*b
gen jal=100*ll
gen jau=100*ul

keep ja*

svmat B, names(col)
keep b ll ul ja*
gen rep=100*b
gen rel=100*ll
gen reu=100*ul

keep ja* re*

svmat C, names(col)
keep b ll ul ja* re*
gen esp=100*b
gen esl=100*ll
gen esu=100*ul

keep re* ja* es*

gen orig= 4.5+(_n)/2 if _n <22


		twoway ///
		(line jal orig, lcolor(black) lpattern(longdash)) ///
		(line jap orig, lcolor(black)) ///
		(line jau orig, lcolor(black) lpattern(longdash)) ///
		(line rel orig, lcolor(gs9) lpattern(longdash)) ///
		(line rep orig, lcolor(gs9)) ///
		(line reu orig, lcolor(gs9) lpattern(longdash)) ///
		(line esl orig, lcolor(gs13) lpattern(longdash)) ///
		(line esp orig, lcolor(gs13)) ///
		(line esu orig, lcolor(gs13) lpattern(longdash)) ///
		,ytitle("Percentage point difference with native-born") ylabel(-50(10)10, valuelabel angle(0)) ///
		yline(0, lstyle(foreground)) ysize(4) ///
		ylabel(,nogrid) ///
		xlabel(5(1)15) graphregion(color(white)) ysc(titlegap(2)) xsc(titlegap(3)) xtitle("Unemployment Benefit Generosity" " ") ///
		leg(order(2 "< 5 years" 5 "5 - 9 years" 8 "> 9 years" ) position(6) cols(3))	

graph export "reg-re.eps", replace


************Robustness checks******************
		
use "t-set", clear

*Alternative specifications

**OLS

svyset ctnum || year

svy: reg ub c.tr1 c.tr2 c.tr3 c.sgen $ses ///
c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
c.ssk c.smipex c.sgdp1 ///
c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.sgen#c.ssk ///
c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.sgen#c.smipex ///
c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.sgen#c.sgdp1 ///
, noomitted
estadd scalar n=201611
estadd scalar cl=112
est store ols


**Sub-indicators as dependent variables
global sub scon scov swait sdur srep

foreach x in sgen $sub {

	global int
	foreach z in $ses {
		global int $int c.`x'#`z'
	}
	meqrlogit ub c.tr1 c.tr2 c.tr3 c.`x' $ses ///
	c.`x'#c.tr1 $itr1 c.`x'#c.tr2 $itr2 c.`x'#c.tr3 $itr3 $int ///
	c.ssk c.smipex c.sgdp1 ///
	c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.`x'#c.ssk ///
	c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.`x'#c.smipex ///
	c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.`x'#c.sgdp1 ///
	|| ctyear:, mle intpoints(10) stddev noomitted
	matrix A=e(N_g)
	estadd scalar cl=A[1,1]
	estadd scalar n=e(N)
	estat icc
	estadd scalar icc=r(icc2)
	est store `x'
}


global rob "tr1 tr2 tr3 X c.X#c.tr1 c.X#c.tr2 c.X#c.tr3 _cons"

global ind 
foreach x in sgen ols $sub {
	global ind $ind `x' X 
	foreach y in 1 2 3 {
	global ind $ind c.`x'#c.tr`y' c.X#c.tr`y'
	}
}

esttab sgen ols $sub using "regress-alt.tex", ///
stats(n cl icc ll, labels("Observations" "Clusters" "Intra-cluster correlation" "Log-likelihood") fmt(%8.0f %8.0f %8.2f %8.0f)) ///
replace compress label booktabs nodepvars se(2) b(2) ///
mtitles("Logit" "OLS" "Qualifying" "Coverage" "Waiting" "Duration" "Replacement" ) nonum noomitted ///
order($rob) ///
keep($rob) ///
eqlabels("" "") transform(ln*: exp(@) exp(@)) ///
addnote("Interacted controls are included in all models") ///
rename($ind) ///
varlabels(	eq1:_cons "Average intercept (native-born)" lns1_1_1:_cons "Standard deviation of the intercepts" ///
			X "\textit{Indicator}" ///
			c.X#c.tr1 "\textit{indicator} $\times$ < 5 years of residency " ///
			c.X#c.tr2 "\textit{indicator} $\times$ 5 -- 9 years of residency " ///
			c.X#c.tr3 "\textit{indicator} $\times$> 9 years of residency " )


*Country of birth		
			
**Without Germany

meqrlogit ub c.tr1 c.tr2 c.tr3 c.sgen $ses ///
c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
c.ssk c.smipex c.sgdp1 ///
c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.sgen#c.ssk ///
c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.sgen#c.smipex ///
c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.sgen#c.sgdp1 ///
if country!="DE" ///
|| ctyear:, mle intpoints(10) stddev noomitted
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store wde



**Country of birth

meqrlogit ub c.etr1 c.etr2 c.otr1 c.otr2 c.sgen $ses ///
c.sgen#c.etr1 $ietr1 c.sgen#c.etr2 $ietr2  $isgen ///
c.sgen#c.otr1 $iotr1 c.sgen#c.otr2 $iotr2 ///
c.ssk c.smipex c.sgdp1 ///
c.ssk#c.etr1 c.ssk#c.etr2  c.sgen#c.ssk ///
c.ssk#c.otr1 c.ssk#c.otr2 ///
c.smipex#c.etr1 c.smipex#c.etr2  c.sgen#c.smipex ///
c.smipex#c.otr1 c.smipex#c.otr2 ///
c.sgdp1#c.etr1 c.sgdp1#c.etr2  c.sgen#c.sgdp1 ///
c.sgdp1#c.otr1 c.sgdp1#c.otr2 ///
if country!="DE" ///
|| ctyear:, mle intpoints(10) stddev noomitted
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store cbi


global cbi "tr1 tr2 tr3 etr1 etr2 otr1 otr2 sgen c.sgen#c.tr1 c.sgen#c.tr2 c.sgen#c.tr3 c.sgen#c.etr1 c.sgen#c.etr2 c.sgen#c.otr1 c.sgen#c.otr2 _cons"

esttab sgen wde cbi using "regress-cbi.tex", ///
stats(n cl icc ll, labels("Observations" "Clusters" "Intra-cluster correlation" "Log-likelihood") fmt(%8.0f %8.0f %8.2f %8.0f)) ///
replace compress label booktabs nodepvars se(2) b(2) ///
mtitles("All countries" "Excluding Germany" "Country of birth") nonum noomitted ///
order($cbi) ///
keep($cbi) ///
eqlabels("" "") transform(ln*: exp(@) exp(@)) ///
addnote("Interacted controls are included in all models") ///
varlabels(	eq1:_cons "Average intercept (native-born)" lns1_1_1:_cons "Standard deviation of the intercepts")



*Various points in time

foreach v in 1 2 3 4 {
	use "t`v'", clear
	
	*Standardize sample
	qui reg ub tfob c.age $std
	gen n=e(sample)
	keep if n==1

	egen sage=std(age)
	gen sage_sq=sage*sage
	la var sage "Age"
	la var sage_sq "Age$^2$"

	meqrlogit ub c.tfob c.sgen $ses ///
	c.sgen#c.tfob $itfob $isgen ///
	c.ssk c.smipex c.sgdp1 ///
	c.ssk#c.tfob c.sgen#c.ssk ///
	c.smipex#c.tfob c.sgen#c.smipex ///
	c.sgdp1#c.tfob c.sgen#c.sgdp1 ///
	|| ctyear:, mle intpoints(10) stddev noomitted
	matrix A=e(N_g)
	estadd scalar cl=A[1,1]
	estadd scalar n=e(N)
	estat icc
	estadd scalar icc=r(icc2)
	est store t`v'
}


global time "tfob sgen c.sgen#c.tfob _cons"

esttab t1 t2 t3 t4 using "reg-time.tex", ///
stats(n cl icc ll, labels("Observations" "Clusters" "Intra-cluster correlation" "Log-likelihood") fmt(%8.0f %8.0f %8.2f %8.0f)) ///
replace compress label booktabs nodepvars se(2) b(2) ///
mtitles("2005-07" "2008-10" "2011-13" "2014-17") nonum noomitted ///
order($time) ///
keep($time) ///
eqlabels("" "") transform(ln*: exp(@) exp(@)) ///
addnote("Interacted controls are included in all models (not shown here)") ///
varlabels(eq1:_cons "Average intercept (native-born)" lns1_1_1:_cons "Standard deviation of the intercepts") 



* Drop individual countries

use "t-set", clear

foreach x in $ctr {
	di "`x'"
	meqrlogit ub c.tr1 c.tr2 c.tr3 c.sgen $ses ///
	c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
	c.ssk c.smipex c.sgdp1 ///
	c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.sgen#c.ssk ///
	c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.sgen#c.smipex ///
	c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.sgen#c.sgdp1 ///
	if country!="`x'" ///
	|| ctyear:, mle intpoints(10) stddev noomitted
	matrix A=e(N_g)
	estadd scalar cl=A[1,1]
	estadd scalar n=e(N)
	estat icc
	estadd scalar icc=r(icc2)
	est store `x'
}

global drop "tr1 tr2 tr3 sgen c.sgen#c.tr1 c.sgen#c.tr2 c.sgen#c.tr3 _cons"

esttab $ctr using "regress-ctr.tex", ///
stats(n cl icc ll, ///
labels("Observations" "Clusters" "Intra-cluster correlation" "Log-likelihood") fmt(%8.0f %8.0f %8.2f %8.0f)) ///
replace compress label booktabs nodepvars se(2) b(2) ///
mtitles("AT" "BE" "DE" "DK" "EL" "ES" "FI" "FR" "IE" "IT" "NL" "PT" "SE" "UK") nonum noomitted ///
order($drop) ///
keep($drop) ///
eqlabels("" "") transform(ln*: exp(@) exp(@)) ///
addnote("Interacted controls are included in all models") ///
varlabels(	eq1:_cons "Average intercept (native-born)" lns1_1_1:_cons "Standard deviation of the intercepts")


* Different age groups

global drop "tr1 tr2 tr3 sgen c.sgen#c.tr1 c.sgen#c.tr2 c.sgen#c.tr3 _cons"

use "t-set", clear

gen agr=1 if age<30
replace agr=2 if age>=30 & age<=50
replace agr=3 if age>50


foreach x in 1 2 3  {
	di "`x'"
	meqrlogit ub c.tr1 c.tr2 c.tr3 c.sgen $ses ///
	c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
	c.ssk c.smipex c.sgdp1 ///
	c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.sgen#c.ssk ///
	c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.sgen#c.smipex ///
	c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.sgen#c.sgdp1 ///
	if agr==`x' ///
	|| ctyear:, mle intpoints(10) stddev noomitted
	matrix A=e(N_g)
	estadd scalar cl=A[1,1]
	estadd scalar n=e(N)
	estat icc
	estadd scalar icc=r(icc2)
	est store agr`x'
}


esttab agr1 agr2 agr3 using "regress-agr.tex", ///
stats(n cl icc ll, ///
labels("Observations" "Clusters" "Intra-cluster correlation" "Log-likelihood") fmt(%8.0f %8.0f %8.2f %8.0f)) ///
replace compress label booktabs nodepvars se(2) b(2) ///
mtitles("<30" "30-50" ">50") nonum noomitted ///
order($drop) ///
keep($drop) ///
eqlabels("" "") transform(ln*: exp(@) exp(@)) ///
addnote("Interacted controls are included in all models") ///
varlabels(	eq1:_cons "Average intercept (native-born)" lns1_1_1:_cons "Standard deviation of the intercepts")



* Other benefits

use "t-set", clear

global drop "tr1 tr2 tr3 sgen c.sgen#c.tr1 c.sgen#c.tr2 c.sgen#c.tr3 _cons"


foreach x in ub fb hb ab {
	di "`x'"
	meqrlogit `x' c.tr1 c.tr2 c.tr3 c.sgen $ses ///
	c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
	c.ssk c.smipex c.sgdp1 ///
	c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.sgen#c.ssk ///
	c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.sgen#c.smipex ///
	c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.sgen#c.sgdp1 ///
	|| ctyear:, mle intpoints(10) stddev noomitted
	matrix A=e(N_g)
	estadd scalar cl=A[1,1]
	estadd scalar n=e(N) 
	estat icc
	estadd scalar icc=r(icc2)
	est store `x'
}


esttab ub fb hb ab using "regress-otben.tex", ///
stats(n cl icc ll, ///
labels("Observations" "Clusters" "Intra-cluster correlation" "Log-likelihood") fmt(%8.0f %8.0f %8.2f %8.0f)) ///
replace compress label booktabs nodepvars se(2) b(2) ///
mtitles("Unemployment" "Family" "Housing" "Social exclusion") nonum noomitted ///
order($drop) ///
keep($drop) ///
eqlabels("" "") transform(ln*: exp(@) exp(@)) ///
addnote("Interacted controls are included in all models") ///
varlabels(	eq1:_cons "Average intercept (native-born)" lns1_1_1:_cons "Standard deviation of the intercepts")



*Country clusters

use "t-set", clear

generate regime=1
replace regime=2 if ///
country=="SE" | country=="DK" | country=="FI"
replace regime=3 if /// 
country=="PT" | country=="EL" | country=="ES" | country=="IT"
replace regime=4 if /// 
country=="IE" | country=="UK"

la var regime "Country clusters"
la define regime_la 1 "Continental Western Europe" 2 "Nordic countries" 3 "South Europe" 4 "British Isles"
la values regime regime_la

global drop "tr1 tr2 tr3 sgen c.sgen#c.tr1 c.sgen#c.tr2 c.sgen#c.tr3 ssk smipex sgdp1 2.regime 3.regime 4.regime  _cons"


meqrlogit ub c.tr1 c.tr2 c.tr3 c.sgen $ses ///
c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
c.ssk c.smipex c.sgdp1 ///
c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.sgen#c.ssk ///
c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.sgen#c.smipex ///
c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.sgen#c.sgdp1 ///
|| ctyear:, mle intpoints(10) stddev noomitted
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store or


meqrlogit ub c.tr1 c.tr2 c.tr3 c.sgen $ses ///
c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
ib1.regime ///
ib1.regime#c.tr1 ib1.regime#c.tr2 ib1.regime#c.tr3  c.sgen#ib1.regime ///
|| ctyear:, mle intpoints(10) stddev noomitted
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store cl


meqrlogit ub c.tr1 c.tr2 c.tr3 c.sgen $ses ///
c.sgen#c.tr1  $itr1 c.sgen#c.tr2 $itr2 c.sgen#c.tr3 $itr3 $isgen ///
ib1.regime ///
ib1.regime#c.tr1 ib1.regime#c.tr2 ib1.regime#c.tr3  c.sgen#ib1.regime ///
c.ssk c.smipex c.sgdp1 ///
c.ssk#c.tr1 c.ssk#c.tr2 c.ssk#c.tr3  c.sgen#c.ssk ///
c.smipex#c.tr1 c.smipex#c.tr2 c.smipex#c.tr3 c.sgen#c.smipex ///
c.sgdp1#c.tr1 c.sgdp1#c.tr2 c.sgdp1#c.tr3 c.sgen#c.sgdp1 ///
|| ctyear:, mle intpoints(10) stddev noomitted
matrix A=e(N_g)
estadd scalar cl=A[1,1]
estadd scalar n=e(N)
estat icc
estadd scalar icc=r(icc2)
est store co



esttab or cl co using "regress-clusters.tex", ///
stats(n cl icc ll, ///
labels("Observations" "Clusters" "Intra-cluster correlation" "Log-likelihood") fmt(%8.0f %8.0f %8.2f %8.0f)) ///
replace compress label booktabs nodepvars se(2) b(2) ///
mtitles("Variables" "Clusters" "Variables and Clusters") nonum noomitted ///
order($drop) ///
keep($drop) ///
eqlabels("" "") transform(ln*: exp(@) exp(@)) ///
addnote("Interacted controls are included in all models") ///
varlabels(	eq1:_cons "Average intercept (native-born)" lns1_1_1:_cons "Standard deviation of the intercepts")





log close
